﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{
    public partial class Scanlocation : Form
    {
     public WebPor.Service1 lc = new WebPor.Service1();
        //bool c = false;
        //String mawb_no = String.Empty;
        int index;
        string storepcs,location,userid = string.Empty;
        DataSet ds = new DataSet();

        public Scanlocation( string user ,string mawb_no,int index)
        {
            lc.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            InitializeComponent();
          //  this.c = mes;
            //this.mawb_no = mawb;
            this.index = index;
            this.userid = user;
            
            ds = lc.Getdata(mawb_no);
            if (ds==null)
            {
                label11.Visible = true;
                label11.Text = "Data not found";
            }
            else
            {
                Setdata(ds, index);
            }
          
        }

       
        private void menuItem2_Click(object sender, EventArgs e)
        {

            if (ds==null)
            {
                label11.Visible = true;
                label11.Text = "Data not found";
              
            }
            else
            {
                //Call Service validate Location
                lc.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
                bool lo = lc.VaridateLocation(loc);
               
                

                if(lo)                                  //(loc == "a101" || loc == "A101" || loc == "b101" || loc == "B101")
                {
                    textBox3.Focus();
                    storepcs = textBox3.Text;
                   // int cbal = int.Parse(storepcs);
                    if (storepcs != "")
                    {
                        int cpcs = int.Parse(storepcs);
                        if (cpcs > bal || cpcs < 0)
                        {
                            label11.Visible = true;
                            label11.Text = "Invalid Piece Count";
                        }
                        else
                        {
                            location = loc ; 
                            Form5 f5 = new Form5(userid, ds, index, storepcs , location);
                            f5.Show();
                        }
                    }
                    else
                    {
                        label11.Visible = true;
                        label11.Text = "Plese enter piece count";
                    }
                }
                else
                {
                    label11.Visible = true;
                    label11.Text = "Location does not exist";
                }  
            }
        }
        //string mawb_no;
        string loc = string.Empty;
       // DataSet ds = new DataSet();
        int total, store, bal = 0;
        public void Setdata(DataSet getdata,int row)
        {
            if (ds == null)
            {
                MessageBox.Show("data error");
            }
            else
            {
                total=0;store=0;bal = 0;
                label6.Text = ds.Tables[0].Rows[row]["display_mawb"].ToString();
                label5.Text = ds.Tables[0].Rows[row]["total_piece_count"].ToString();
                total=Convert.ToInt32(ds.Tables[0].Rows[row]["total_piece_count"]);
                label9.Text = ds.Tables[0].Rows[row]["stored_piece_count"].ToString();
                store=Convert.ToInt32(ds.Tables[0].Rows[row]["stored_piece_count"]);
                bal = total-store;
                label10.Text = bal.ToString();
                    

            }
           
            
        }


        private void menuItem1_Click(object sender, EventArgs e)
        {
            ScanMAWB ScanMAWB = new ScanMAWB(userid);
            ScanMAWB.Show();
            this.Close();
        }


        public void textBox2_TextChanged(object sender, EventArgs e)
        {
        int numC=textBox2.TextLength;
        if (numC > 4)
        {
            textBox2.Text = "";
            
        }
        else if (numC==4)
        {
            textBox3.Focus();
            loc = textBox2.Text;
        }
        else 
        {
            
            loc = textBox2.Text;
          
            
        }
       
       
        }

        private void button1_Click(object sender, EventArgs e)
        {
            weighloc w = new weighloc(userid, ds, index);
            w.Show();
        }

        private void label4_ParentChanged(object sender, EventArgs e)
        {

        }

    }
}